home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- *
- * Copyright (c) 1992 Silicon Graphics, Inc.
- * All Rights Reserved
- *
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
- *
- * The copyright notice above does not evidence any actual of intended
- * publication of such source code, and is an unpublished work by Silicon
- * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
- * the property of Silicon Graphics, Inc. Any use, duplication or
- * disclosure not specifically authorized by Silicon Graphics is strictly
- * prohibited.
- *
- * RESTRICTED RIGHTS LEGEND:
- *
- * Use, duplication or disclosure by the Government is subject to
- * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
- * Technical Data and Computer Software clause at DFARS 52.227-7013,
- * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
- * Supplement. Unpublished - rights reserved under the Copyright Laws of
- * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
- * Shoreline Blvd., Mountain View, CA 94039-7311
- **************************************************************************
- *
- * File: linfo.c
- *
- * Description: Sample program that demonstrates the use of the local
- * form of the libpod info read and write functions.
- *
- * Usage: linfo printer_name [printer_opt_string]
- *
- * If printer_opt_string is specified, it is expected to be a quoted
- * string describing any optional equipment the the specified printer
- * may contain. An empty string indicates no optional equipment.
- * An attempt is made to write the optional equipment information into
- * the specified printer's configuration file.
- *
- * If printer_opt_string is not specified, the current configuration
- * and status information is displayed.
- *
- * Note: You must have root or lp permissions to successfully run
- * this program to write the config file. There is no such
- * restriction on reading the config or status files.
- *
- **************************************************************************/
-
-
- #ident "$Revision: 1.4 $"
-
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- #include <pod.h>
-
-
- #define HANDLE_ERROR(pname) { \
- PDPerror(pname); \
- exit(1); \
- }
-
-
- void usage(char*);
- void disp_info(PDInfoStruct*, time_t*);
- void disp_opstatus(int);
- void disp_status(PDStatusStruct*, PDMessageStruct*);
- void disp_config(PDInfoStruct*);
- void disp_colorspace(int);
- void disp_depth(int);
- void disp_format(int);
- void disp_pagesize(PDSizeTableStruct*);
-
-
- int main(int argc, char **argv)
- {
- PDInfoStruct *info, pod_info;
- time_t mod_time;
-
- /*
- * Get the printer name from command line
- */
- if (argc < 2) {
- usage(argv[0]);
- exit(1);
- }
-
- /*
- * Handle the printer options change request
- */
- if (argc == 3) {
- /*
- * Read full info and display current optional equipment
- */
- if (PDLocalReadInfo(argv[1], &info, &mod_time) < 0)
- HANDLE_ERROR(argv[0]);
- (void)printf("Original optional equipment: \"%s\"\n",
- info->printer_options);
-
- /*
- * Copy the info structure and et active_status to NULL
- * thereby indicating that the status file should not be written
- * only the config file.
- */
- pod_info = *info;
- pod_info.active_status = NULL;
-
- /*
- * Copy the new printer options string into the info struct
- */
- (void)strncpy(pod_info.printer_options, argv[2], PD_STR_MAX);
- pod_info.printer_options[PD_STR_MAX-1] = '\0';
-
- /*
- * Now attempt to write new config file and display what
- * was written.
- */
- if (PDLocalWriteInfo(argv[1], &pod_info) < 0)
- HANDLE_ERROR(argv[0]);
- (void)printf("New optional equipment: \"%s\"\n\n",
- pod_info.printer_options);
- }
-
- /*
- * Read and display info structure
- */
- if (PDLocalReadInfo(argv[1], &info, &mod_time) < 0)
- HANDLE_ERROR(argv[0]);
- disp_info(info, &mod_time);
-
- return 0;
- }
-
-
- void usage(char *progname)
- {
- (void)fprintf(stderr, "Usage: %s printer_name\n", progname);
- }
-
-
- void disp_info(PDInfoStruct *info, time_t *mod_timep)
- {
- (void)printf("Last Information Modification: %s\n", ctime(mod_timep));
- (void)printf("Status Information\n");
- disp_status(info->active_status, info->error_status);
- (void)printf("\nConfiguration Information\n");
- disp_config(info);
- }
-
-
- void disp_status(PDStatusStruct *status, PDMessageStruct *messages)
- {
- register int i;
- char *options;
-
- disp_opstatus(status->operational_status);
- (void)printf("\tMedia type code: %d\n", status->media_type);
- (void)printf("\tNumber of colors code: 0x%08X\n",
- status->number_of_colors);
- (void)printf("\t\tNumber of colors: %d\n",
- PD_GET_NUMCOLORS(status->number_of_colors));
- disp_colorspace(PD_GET_COLORSPACE_CODE(status->number_of_colors));
- disp_depth(PD_GET_DEPTH_CODE(status->number_of_colors));
- disp_format(PD_GET_FORMAT_CODE(status->number_of_colors));
- (void)printf("\tMedia size code: 0x%08X\n", status->media_size);
- (void)printf("\tMedia size name: %s\n",
- PDGetNameBySizeCode(status->media_size));
- options = status->printer_options;
- (void)printf("\tInstalled options: %s\n",
- (options && *options != '\0') ? options: "None");
- (void)printf("\tMedia size validation mask: %d\n", status->validation_mask);
- (void)printf("\tNumber of messages: %d\n", status->error_count);
- for (i = 0; i < status->error_count; i++) {
- (void)printf("\n\t\tMessage %d code: 0x%08X\n", i+1,
- messages[i].message_code);
- (void)printf("\t\tMessage %d text: %s\n", i+1,
- messages[i].message_text);
- }
- }
-
-
- void disp_opstatus(int status)
- {
- (void)printf("\tOperational status: ");
- switch(status) {
- case PD_STATUS_IDLE:
- (void)printf("IDLE");
- break;
- case PD_STATUS_BUSY:
- (void)printf("BUSY");
- break;
- case PD_STATUS_FAULTED:
- (void)printf("FAULTED");
- break;
- case PD_STATUS_UNAVAILABLE:
- (void)printf("UNAVAILABLE");
- break;
- default:
- (void)printf("UNKNOWN");
- break;
- }
- (void)printf("\n");
- }
-
-
- void disp_config(PDInfoStruct *info)
- {
- register int i;
-
- (void)printf("\tPrinter class: %s\n", info->printer_class);
- (void)printf("\tPrinter model: %s\n", info->printer_model);
- (void)printf("\tPrinter options: %s\n", info->printer_options);
- (void)printf("\tLocation code: %s\n", info->location_code);
- (void)printf("\tPhysical location: %s\n", info->physical_location);
- (void)printf("\tTechnology: %s\n", info->technology);
- (void)printf("\n");
-
- (void)printf("\tConfig file pathname: %s\n", info->config_path);
- (void)printf("\tDriver pathname: %s\n", info->driver_path);
- (void)printf("\tPort pathname: %s\n", info->port_path);
- (void)printf("\tStatus file pathname: %s\n", info->active_path);
- (void)printf("\n");
-
- (void)printf("\tError retry wait: %d\n", info->error_retry_wait);
- (void)printf("\tStatus update wait: %d\n", info->status_update_wait);
- (void)printf("\tMedia wait: %d\n", info->media_wait);
- (void)printf("\n");
-
- (void)printf("\tHorizontal resolution: %d\n", info->horizontal_resolution);
- (void)printf("\tVertical resolution: %d\n", info->vertical_resolution);
- (void)printf("\n");
-
- (void)printf("\tCost per page: %f\n", info->cost_per_page);
- (void)printf("\tAve. time per page: %d\n", info->avg_time_per_page);
- (void)printf("\tMax. time per page: %d\n", info->max_time_per_page);
- (void)printf("\n");
-
- (void)printf("\tMin. number of colors: %d\n", info->min_number_of_colors);
- (void)printf("\tMax. number of colors: %d\n", info->max_number_of_colors);
- (void)printf("\n");
-
- (void)printf("\tMin. horizontal area (in.): %f\n",
- info->min_area_horizontal);
- (void)printf("\tMin. vertical area (in.): %f\n", info->min_area_vertical);
- (void)printf("\tMax. horizontal area (in.): %f\n",
- info->max_area_horizontal);
- (void)printf("\tMax. vertical area (in.): %f\n", info->max_area_vertical);
- (void)printf("\n");
-
- (void)printf("\tMin. horizontal area (dots): %d\n",
- info->min_addr_horizontal);
- (void)printf("\tMin. vertical area (dots): %d\n", info->min_addr_vertical);
- (void)printf("\tMax. horizontal area (dots): %d\n",
- info->max_addr_horizontal);
- (void)printf("\tMax. vertical area (dots): %d\n", info->max_addr_vertical);
- (void)printf("\n");
-
- (void)printf("\tNumber of quality modes: %d\n", info->quality_modes);
- for (i = 0; i < info->quality_modes; i++)
- (void)printf("\t\tQuality mode %d: %s\n", i+1,
- info->quality_mode_names[i]);
- if (info->quality_modes)
- (void)printf("\tDefault quality mode: %s\n",
- info->quality_mode_names[info->default_quality_mode-1]);
- (void)printf("\n");
-
- (void)printf("\tManual capable: %s\n", (info->manual_capable) ?
- "Yes": "No");
- (void)printf("\tBlack substitute: %s\n", (info->black_substitute) ?
- "Yes": "No");
- (void)printf("\tMedia standard: %d\n", info->media_standard);
- (void)printf("\n");
-
- (void)printf("\tNumber of fonts: %d\n", info->avail_fonts);
- for (i = 0; i < info->avail_fonts; i++)
- (void)printf("\t\tFont name %d: %s\n", i+1, info->avail_fonts_names[i]);
- (void)printf("\n");
-
- (void)printf("\tNumber of input sources: %d\n", info->input_sources);
- for (i = 0; i < info->input_sources; i++)
- (void)printf("\t\tInput source %d: %s\n", i+1,
- info->input_sources_names[i]);
- if (info->input_sources)
- (void)printf("\tDefault input source: %s\n",
- info->input_sources_names[info->default_input_source-1]);
- (void)printf("\tInput source gamma: %f\n", info->input_source_gamma);
- (void)printf("\n");
-
- (void)printf("\tNumber of color adj. schemes: %d\n",
- info->color_adjustment);
- for (i = 0; i < info->color_adjustment; i++)
- (void)printf("\t\tAdj. scheme %d: %s\n", i+1, info->color_adj_names[i]);
- if (info->color_adjustment)
- (void)printf("\tDefault adj. scheme: %s\n",
- info->color_adj_names[info->default_color_adj-1]);
- (void)printf("\n");
-
- (void)printf("\tNumber of media types: %d\n", info->media_types);
- for (i = 0; i < info->media_types; i++)
- (void)printf("\t\tMedia type %d: %s\n", i+1,
- info->media_types_names[i]);
- if (info->media_types)
- (void)printf("\tDefault media type: %s\n",
- info->media_types_names[info->default_media_type-1]);
- (void)printf("\n");
-
- (void)printf("\tNumber of size table entries: %d\n",
- info->size_table_entries);
- for (i = 0; i < info->size_table_entries; i++) {
- (void)printf("\t\tEntry %d:\n", i+1);
- disp_pagesize(&info->size_table[i]);
- }
- (void)printf("\n");
- }
-
-
- void disp_colorspace(int cspace)
- {
- (void)printf("\t\tColorspace: ");
- switch(cspace) {
- case PD_DATA_K:
- (void)printf("k\n");
- break;
- case PD_DATA_CMY:
- (void)printf("cmy\n");
- break;
- case PD_DATA_CMYK:
- (void)printf("cmyk\n");
- break;
- case PD_DATA_W:
- (void)printf("w\n");
- break;
- case PD_DATA_RGB:
- (void)printf("rgb\n");
- break;
- case PD_DATA_YMC:
- (void)printf("ymc\n");
- break;
- case PD_DATA_YMCK:
- (void)printf("ymck\n");
- break;
- case PD_DATA_KCMY:
- (void)printf("kcmy\n");
- break;
- default:
- (void)printf("0x%08X\n", cspace);
- break;
- }
- }
-
-
- void disp_depth(int depth)
- {
- (void)printf("\t\tDepth: ");
- switch(depth) {
- case PD_DATA_DEPTH1:
- (void)printf("1 bpp\n");
- break;
- case PD_DATA_DEPTH4:
- (void)printf("4 bpp\n");
- break;
- case PD_DATA_DEPTH8:
- (void)printf("8 bpp\n");
- break;
- default:
- (void)printf("0x%08X\n", depth);
- break;
- }
- }
-
-
- void disp_format(int format)
- {
- (void)printf("\t\tFormat: ");
- switch(format) {
- case PD_DATA_CHUNKY:
- (void)printf("chunky\n");
- break;
- case PD_DATA_BANDED:
- (void)printf("banded\n");
- break;
- case PD_DATA_PLANAR:
- (void)printf("planar\n");
- break;
- default:
- (void)printf("0x%08X\n", format);
- break;
- }
- }
-
-
- void disp_pagesize(PDSizeTableStruct *size_info)
- {
- (void)printf("\t\t\tMedia size: 0x%08X %s\n", size_info->media_size,
- PDGetNameBySizeCode(size_info->media_size));
- (void)printf( "\t\t\tOverall dimensions (inches): %.3f (h) by %.3f (v)\n",
- size_info->width, size_info->length);
- (void)printf("\t\t\tMargins (inches): %.3f (l), %.3f (t)\n",
- size_info->left_margin, size_info->top_margin);
- (void)printf("\t\t\tImageable dimensions (dots): %d (h) by %d (v)\n",
- size_info->horizontal_addr, size_info->vertical_addr);
- (void)printf("\t\t\tRaster definition code: 0x%02X\n",
- size_info->raster_definition);
- (void)printf("\t\t\tValidation mask: 0x%02X\n", size_info->validation_mask);
- (void)printf("\t\t\tVariable page size code: 0x%02X\n",
- size_info->variable_page_size);
- }
-